public class DeadLockDemo {
    private static Object o1 = new Object();
    private static Object o2 = new Object();

    public static void main(String[] args) {
        new Thread(()->{
            synchronized (o1){
                System.out.println(Thread.currentThread().getName() + "get o1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "waiting get o2");
                synchronized (o2){
                    System.out.println(Thread.currentThread().getName() + "get o2");
                }
            }
        }, "线程1").start();

        new Thread(() ->{
            synchronized (o2){
                System.out.println(Thread.currentThread().getName() + "get o1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "waiting get o1");
                synchronized (o1){
                    System.out.println(Thread.currentThread().getName() + "get o1");
                }
            }
        }, "线程2").start();

    }


}
